package com.shenda.consumer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.google.common.eventbus.Subscribe;
import com.shenda.api.entity.Data;
import com.shenda.api.service.DatasServiceAsync;
import com.swak.annotation.FluxReferer;
import com.swak.utils.JsonMapper;

/**
 * 上传完成消费
 * 
 * @author lifeng
 */
@Component
public class DatasConsumer {

	private Logger logger = LoggerFactory.getLogger(DatasConsumer.class);

	/**
	 * 数据服务
	 */
	@FluxReferer
	private DatasServiceAsync datasService;

	/**
	 * 处理消费事件
	 * 
	 * @param data
	 */
	@Subscribe
	public void message(Data data) {
		datasService.save(data).whenComplete((v, e) -> {
			if (e != null) {
				logger.error("数据上传成功，入库失败:[{}]", JsonMapper.toJson(data));
			}
		});
	}
}